home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / prefix / RCS / prefix.c,v < prev    next >
Encoding:
Text File  |  1992-03-27  |  22.5 KB  |  955 lines

  1. head     1.11;
  2. branch   ;
  3. access   ;
  4. symbols  sprited:1.11.1;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.11
  10. date     92.03.25.15.53.12;  author shirriff;  state Exp;
  11. branches 1.11.1.1;
  12. next     1.10;
  13.  
  14. 1.10
  15. date     92.01.13.18.08.20;  author rab;  state Exp;
  16. branches ;
  17. next     1.9;
  18.  
  19. 1.9
  20. date     91.10.25.15.57.01;  author rab;  state Exp;
  21. branches ;
  22. next     1.8;
  23.  
  24. 1.8
  25. date     91.08.26.21.00.46;  author rab;  state Exp;
  26. branches ;
  27. next     1.7;
  28.  
  29. 1.7
  30. date     91.08.26.18.11.05;  author brent;  state Exp;
  31. branches ;
  32. next     1.6;
  33.  
  34. 1.6
  35. date     89.06.19.14.29.31;  author jhh;  state Exp;
  36. branches ;
  37. next     1.5;
  38.  
  39. 1.5
  40. date     88.10.31.09.38.50;  author brent;  state Exp;
  41. branches ;
  42. next     1.4;
  43.  
  44. 1.4
  45. date     88.09.12.13.32.19;  author brent;  state Exp;
  46. branches ;
  47. next     1.3;
  48.  
  49. 1.3
  50. date     88.08.07.17.37.10;  author ouster;  state Exp;
  51. branches ;
  52. next     1.2;
  53.  
  54. 1.2
  55. date     88.08.07.15.05.25;  author ouster;  state Exp;
  56. branches ;
  57. next     1.1;
  58.  
  59. 1.1
  60. date     88.08.07.14.43.03;  author ouster;  state Exp;
  61. branches ;
  62. next     ;
  63.  
  64. 1.11.1.1
  65. date     92.03.26.17.43.48;  author kupfer;  state Exp;
  66. branches ;
  67. next     ;
  68.  
  69.  
  70. desc
  71. @@
  72.  
  73.  
  74. 1.11
  75. log
  76. @Added force mount flag
  77. @
  78. text
  79. @/* 
  80.  * prefix.c --
  81.  *
  82.  *    Program to print and manipulate the prefix table.
  83.  *
  84.  * Copyright 1988 Regents of the University of California
  85.  * Permission to use, copy, modify, and distribute this
  86.  * software and its documentation for any purpose and without
  87.  * fee is hereby granted, provided that the above copyright
  88.  * notice appear in all copies.  The University of California
  89.  * makes no representations about the suitability of this
  90.  * software for any purpose.  It is provided "as is" without
  91.  * express or implied warranty.
  92.  */
  93.  
  94. #ifndef lint
  95. static char rcsid[] = "$Header: /sprite/src/cmds/prefix/RCS/prefix.c,v 1.10 92/01/13 18:08:20 rab Exp Locker: shirriff $ SPRITE (Berkeley)";
  96. #endif not lint
  97.  
  98. #include <fs.h>
  99. #include <fsCmd.h>
  100. #include <host.h>
  101. #include <option.h>
  102. #include <stdio.h>
  103. #include <string.h>
  104. #include <status.h>
  105. #include <sysStats.h>
  106. #include <sys/stat.h>
  107.  
  108. static int PrintPrefixEntry _ARGS_ ((Fs_Prefix *prefixPtr));
  109. static void validateLocalPath _ARGS_ ((char *path, int checkRemote));
  110.  
  111. extern int errno;
  112. static char *programName;
  113.  
  114. /*
  115.  * Command line options.
  116.  */
  117.  
  118. static int print = 0;
  119. static int readOnly = 0;
  120. static int localAccess = 0;
  121. static int force = 0;
  122. static char *loadedPrefix = (char *) NULL;
  123. static char *deviceName = (char *) NULL;
  124. static char *unmountName = (char *) NULL;
  125. static char *exportedPrefix = (char *) NULL;
  126. static char *clearedPrefix = (char *) NULL;
  127. static char *deletedPrefix = (char *) NULL;
  128. static char *Prefix = (char *) NULL;
  129. static char *localPath = (char *) NULL;
  130. static char *addHostName = NULL;
  131. static char *delHostName = NULL;
  132. static char *serverName = NULL;
  133.  
  134. static Option optionArray[] = {
  135.     {OPT_TRUE,   "p", (char *) &print,
  136.     "Print the prefix table or export list"},
  137.     {OPT_STRING, "a", (char *) &loadedPrefix,
  138.     "Next argument is prefix to add"},
  139.     {OPT_STRING,  "s", (char *) &serverName,
  140.     "Next argument is name or id of server for added prefix (use with -a)"},
  141.     {OPT_STRING, "l", (char *) &localPath,
  142.     "Next argument is directory to mount/export (with -x, -M or -U)"},
  143.     {OPT_STRING, "M", (char *) &deviceName,
  144.     "Next argument is device to mount (use -l too)"},
  145.     {OPT_TRUE,     "r", (char *) &readOnly,
  146.     "Mount read only"},
  147.     {OPT_TRUE,     "f", (char *) &force,
  148.     "Force the mount"},
  149.     {OPT_TRUE,     "L", (char *) &localAccess,
  150.     "Mount locally only; do not export"},
  151.     {OPT_STRING, "U", (char *) &unmountName,
  152.     "Next argument is prefix to unmount"},
  153.     {OPT_STRING, "x", (char *) &exportedPrefix, 
  154.     "Next argument is exported prefix (use with -p, -l, or -[hH])"},
  155.     {OPT_STRING, "h", (char *) &addHostName,
  156.     "Next argument is name or id of host to add to export list"},
  157.     {OPT_STRING, "H", (char *) &delHostName,
  158.     "Next argument is name or id of host to delete from export list"},
  159.     {OPT_STRING, "c", (char *) &clearedPrefix,
  160.     "Next argument is prefix to clear handle for"},
  161.     {OPT_STRING, "d", (char *) &deletedPrefix, 
  162.     "Next argument is prefix to delete altogether"},
  163. };
  164.  
  165.  
  166.  
  167. /*
  168.  *----------------------------------------------------------------------
  169.  *
  170.  * main --
  171.  *
  172.  *    Collects arguments and uses Fs_Command to manipulate the
  173.  *    prefix table.
  174.  *
  175.  * Results:
  176.  *    None.
  177.  *
  178.  * Side effects:
  179.  *    Calls Fs_Command...
  180.  *
  181.  *----------------------------------------------------------------------
  182.  */
  183.  
  184. main(argc, argv)
  185.     int argc;
  186.     char *argv[];
  187. {
  188.     register     ReturnStatus status = SUCCESS;    /* status of system calls */
  189.     int     flags;
  190.     int     addHostID = -1;
  191.     int     delHostID = -1;
  192.     int     serverID = FS_NO_SERVER;
  193.     Host_Entry    *entry;
  194.     int        scanned;
  195.     int        temp;
  196.  
  197.     programName = argv[0];
  198.     if (argc == 1) {
  199.     print = 1;
  200.     } else {
  201.     argc = Opt_Parse(argc, argv, optionArray, Opt_Number(optionArray),
  202.         OPT_ALLOW_CLUSTERING);
  203.     }
  204.  
  205.     if (argc != 1) {
  206.     fprintf(stderr, "%s got extraneous argument \"%s\".\n", argv[0],
  207.         argv[1]);
  208.     Opt_PrintUsage(argv[0], optionArray, Opt_Number(optionArray));
  209.     exit(1);
  210.     }
  211.     if (addHostName != (char *) NULL) {
  212.     scanned = sscanf(addHostName, " %d", &temp);
  213.     if (scanned == 1) {
  214.         addHostID = temp;
  215.     } else {
  216.         entry = Host_ByName(addHostName);
  217.         if (entry == NULL) {
  218.         fprintf(stderr, "No such host \"%s\"\n", addHostName);
  219.         exit(1);
  220.         }
  221.         addHostID = entry->id;
  222.     }
  223.     }
  224.     if (delHostName != (char *) NULL) {
  225.     scanned = sscanf(delHostName, " %d", &temp);
  226.     if (scanned == 1) {
  227.         delHostID = temp;
  228.     } else {
  229.         entry = Host_ByName(delHostName);
  230.         if (entry == NULL) {
  231.         fprintf(stderr, "No such host \"%s\"\n", delHostName);
  232.         exit(1);
  233.         }
  234.         delHostID = entry->id;
  235.     }
  236.     }
  237.     if (serverName != (char *) NULL) {
  238.     scanned = sscanf(serverName, " %d", &temp);
  239.     if (scanned == 1) {
  240.         serverID = temp;
  241.     } else {
  242.         entry = Host_ByName(serverName);
  243.         if (entry == NULL) {
  244.         fprintf(stderr, "No such host \"%s\"\n", serverName);
  245.         exit(1);
  246.         }
  247.         serverID = entry->id;
  248.     }
  249.     }
  250.     if (loadedPrefix != (char *) NULL) {
  251.     /*
  252.      * Load a prefix
  253.      *    Load a prefix into the prefix table.
  254.      *    A prefix in the prefix table causes an attempt to find the
  255.      *    server the first time a file is opened under that prefix.
  256.      *      If serverID == FS_NO_SERVER then a broadcast is done,
  257.      *    otherwise the server is contacted directly.
  258.      */
  259.     Fs_PrefixLoadInfo    loadInfo;
  260.  
  261.     (void) strcpy(loadInfo.prefix, loadedPrefix);
  262.     loadInfo.serverID = serverID;
  263.     status = Fs_Command(FS_PREFIX_LOAD, sizeof(Fs_PrefixLoadInfo), 
  264.          &loadInfo);
  265.     if (status != SUCCESS) {
  266.         fprintf(stderr, "%s couldn't load prefix: %s.\n",
  267.             argv[0], Stat_GetMsg(status));
  268.         exit(1);
  269.     }
  270.     }
  271.     if (deviceName != (char *)NULL) {
  272.     if (!force) {
  273.         validateLocalPath(localPath, 1);
  274.     }
  275.     flags = 0;
  276.     if (localAccess) {
  277.         flags |= FS_ATTACH_LOCAL;
  278.     }
  279.     if (readOnly) {
  280.         flags |= FS_ATTACH_READ_ONLY;
  281.     }
  282.     status = Fs_AttachDisk(deviceName, localPath, flags);
  283.     if (status != SUCCESS) {
  284.         fprintf(stderr, "Mount \"%s\" on \"%s\": %s\n", deviceName,
  285.             localPath, Stat_GetMsg(status));
  286.         exit(1);
  287.     }
  288.     localPath = (char *)NULL;
  289.     }
  290.     if (unmountName != (char *)NULL) {
  291.     status = Fs_AttachDisk(deviceName, unmountName, FS_DETACH);
  292.     if (status != SUCCESS) {
  293.         fprintf(stderr, "Unmount \"%s\": %s\n", unmountName,
  294.             Stat_GetMsg(status));
  295.         exit(1);
  296.     }
  297.     }
  298.     if (addHostID != -1 || delHostID != -1) {
  299.     Fs_PrefixControl    prefixControl;
  300.     /*
  301.      * Add or remove a host from a prefix's export list.
  302.      */
  303.     if (exportedPrefix == (char *) NULL) {
  304.         fprintf(stderr, "Specify an exported prefix with -x\n");
  305.         Opt_PrintUsage(argv[0], optionArray, Opt_Number(optionArray));
  306.         exit(1);
  307.     }
  308.     if (addHostID != -1) {
  309.         prefixControl.clientID = addHostID;
  310.         prefixControl.delete = FALSE;
  311.     } else {
  312.         prefixControl.clientID = delHostID;
  313.         prefixControl.delete = TRUE;
  314.     }
  315.     (void) strcpy(prefixControl.prefix, exportedPrefix);
  316.     status = Fs_Command(FS_PREFIX_CONTROL, sizeof(prefixControl),
  317.         &prefixControl);
  318.     if (status != SUCCESS) {
  319.         fprintf(stderr, "%s couldn't add/delete host: %s.\n",
  320.             argv[0], Stat_GetMsg(status));
  321.         exit(1);
  322.     }
  323.     exportedPrefix = (char *) NULL;
  324.     }
  325.     if (exportedPrefix != (char *) NULL) {
  326.     if (print) {
  327.         /*
  328.          * Print the export list of this prefix.
  329.          */
  330.         char buffer[100 * sizeof(int)];
  331.         int *exportList = (int *)buffer;
  332.         (void) strcpy(buffer, exportedPrefix);
  333.         status = Sys_Stats(SYS_FS_PREFIX_EXPORT, sizeof(buffer), buffer);
  334.         if (status != SUCCESS) {
  335.         fprintf(stderr, "%s: couldn't get export list\n",
  336.             exportedPrefix);
  337.         exit(status);
  338.         } else if (*exportList == 0) {
  339.         printf("%s exported to all hosts\n", exportedPrefix);
  340.         } else {
  341.         printf("\"%s\" EXPORT LIST\n", exportedPrefix);
  342.         for ( ; *exportList != 0 ; exportList++) {
  343.             Host_Entry *hostPtr;
  344.             hostPtr = Host_ByID(*exportList);
  345.             if (hostPtr == (Host_Entry *)NULL) {
  346.             break;
  347.             }
  348.             printf("\t<%d> %s\n", hostPtr->id, hostPtr->name);
  349.         }
  350.         }
  351.     } else {
  352.         Fs_TwoPaths args;
  353.  
  354.         /*
  355.          * localPath may be "/", a real directory, when the
  356.          * -x option is used so disable the remote link check
  357.          * in validateLocalPath
  358.          */
  359.         if (!force) {
  360.         validateLocalPath(localPath, 0);
  361.         }
  362.  
  363.         /*
  364.          * Export a prefix.  This is used on a server to explicitly
  365.          * export a local directory under some prefix.
  366.          */
  367.     
  368.         args.pathLen1 = strlen(localPath) + 1;
  369.         args.path1 = localPath;
  370.         args.pathLen2 = strlen(exportedPrefix) + 1;
  371.         args.path2 = exportedPrefix;
  372.     
  373.         status = Fs_Command(FS_PREFIX_EXPORT, sizeof(Fs_TwoPaths), &args);
  374.         if (status != SUCCESS) {
  375.         fprintf(stderr, "%s couldn't export prefix: %s.\n",
  376.             argv[0], Stat_GetMsg(status));
  377.         exit(1);
  378.         }
  379.     }
  380.     }
  381.     if (clearedPrefix != (char *) NULL) {
  382.     /*
  383.      * Clear a prefix's file handle.
  384.      */
  385.     status = Fs_Command(FS_PREFIX_CLEAR, strlen(clearedPrefix) + 1,
  386.         clearedPrefix);
  387.     if (status != SUCCESS) {
  388.         fprintf(stderr, "%s couldn't clear prefix handle: %s.\n",
  389.             argv[0], Stat_GetMsg(status));
  390.         exit(1);
  391.     }
  392.     }
  393.     if (deletedPrefix != (char *) NULL) {
  394.     /*
  395.      * Delete a prefix
  396.      */
  397.     status = Fs_Command(FS_PREFIX_DELETE, strlen(deletedPrefix) + 1,
  398.         deletedPrefix);
  399.     if (status != SUCCESS) {
  400.         fprintf(stderr, "%s couldn't delete prefix: %s.\n",
  401.             argv[0], Stat_GetMsg(status));
  402.         exit(1);
  403.     }
  404.     }
  405.     if (print) {
  406.     register int index;
  407.     Fs_Prefix prefix;
  408.  
  409.     printf("%-20s %-8s %7s %7s %8s\n", 
  410.         "Prefix", "Server", "Domain", "File #", "Version");
  411.     for (index = 0 ; status == SUCCESS; index++) {
  412.         bzero((char *) &prefix, sizeof(Fs_Prefix));
  413.         status = Sys_Stats(SYS_FS_PREFIX_STATS, index, (Address) &prefix);
  414.         if (status == SUCCESS) {
  415.         PrintPrefixEntry(&prefix);
  416.         }
  417.     }
  418.     }
  419.     exit(0);
  420. }
  421.  
  422. /*
  423.  *----------------------------------------------------------------------
  424.  *
  425.  * PrintPrefixEntry --
  426.  *
  427.  *    Print out information for a single prefix table entry.
  428.  *
  429.  * Results:
  430.  *    None.
  431.  *
  432.  * Side effects:
  433.  *    Stuff gets printed.
  434.  *
  435.  *----------------------------------------------------------------------
  436.  */
  437.  
  438. static int 
  439. PrintPrefixEntry(prefixPtr)
  440.     Fs_Prefix *prefixPtr;
  441. {
  442.     static char serverName[9];
  443.     static int  prevServerID = -1;
  444.     Host_Entry  *host;
  445.  
  446.     printf("%-20s", prefixPtr->prefix);
  447.  
  448.     if (prefixPtr->serverID > 0) {
  449.  
  450.     /*
  451.      * If the server ID is the same as the previous entry's ID, then
  452.      * we can reuse serverName and save a call to Host_ByID.
  453.      */
  454.     if (prefixPtr->serverID == prevServerID) {
  455.         printf(" %-8s", serverName);
  456.     } else {
  457.         host = Host_ByID(prefixPtr->serverID);
  458.         if (host != (Host_Entry *)NULL) {
  459.         register int charCnt;
  460.         for (charCnt = 0 ; charCnt < sizeof(serverName) ; charCnt++) {
  461.             if (host->name[charCnt] == '.' ||
  462.             host->name[charCnt] == '\0') {
  463.             serverName[charCnt] = '\0';
  464.             break;
  465.             } else {
  466.             serverName[charCnt] = host->name[charCnt];
  467.             }
  468.         }
  469.         serverName[sizeof(serverName)-1] = '\0';
  470.         printf(" %-8s", serverName);
  471.         prevServerID = prefixPtr->serverID;
  472.         } else {
  473.         printf(" (%d)", prefixPtr->serverID);
  474.         }
  475.     }
  476.     } else {
  477.     printf(" %-8s", "(none)");
  478.     }
  479.  
  480.     printf(" %7d %7d %8d", prefixPtr->domain, prefixPtr->fileNumber, 
  481.         prefixPtr->version);
  482.  
  483.     if (prefixPtr->flags & FS_LOCAL_PREFIX) {
  484.     printf(" local   ");
  485.     }
  486.     if (prefixPtr->flags & FS_IMPORTED_PREFIX) {
  487.     printf(" imported");
  488.     }
  489.     if (prefixPtr->flags & FS_EXPORTED_PREFIX) {
  490.     printf(" exported");
  491.     }
  492.     printf("\n");
  493. }
  494.  
  495. /*
  496.  *----------------------------------------------------------------------
  497.  *
  498.  * validateLocalPath --
  499.  *
  500.  *    Make sure the local path specified with the -l option is valid.
  501.  *    It must be an absolute path starting with '/'.
  502.  *      It must be an already existing remote link if checkRemote == 1.
  503.  *
  504.  * Results:
  505.  *    None.
  506.  *
  507.  * Side effects:
  508.  *    Will exit with an error code of 1 if the path is invalid.
  509.  *
  510.  *----------------------------------------------------------------------
  511.  */
  512.  
  513. static void
  514. validateLocalPath(path, checkRemote)
  515.     char *path;
  516.     int checkRemote;
  517. {
  518.     struct stat statBuf;
  519.  
  520.     if (path == NULL) {
  521.     fprintf(stderr, "%s:  You must specify a local directory with -l\n",
  522.         programName);
  523.     Opt_PrintUsage(programName, optionArray, Opt_Number(optionArray));
  524.     exit(1);
  525.     } else if (*path != '/') {
  526.     fprintf(stderr,
  527.         "%s:  %s is not an absolute path.  It must start with '/'\n",
  528.         programName, path);
  529.     exit(1);
  530.     }
  531.     if (lstat(path, &statBuf) < 0) {
  532.     fprintf(stderr, "%s:  Cannot lstat %s:  %s\n",
  533.         programName, path, strerror(errno));
  534.     exit(1);
  535.     }
  536.     if (checkRemote && (statBuf.st_mode & S_IFMT) != S_IFRLNK) {
  537.     fprintf(stderr, "%s:  %s is not a remote link.\n",
  538.         programName, path);
  539.     exit(1);
  540.     }
  541.     return;
  542. }
  543.  
  544. @
  545.  
  546.  
  547. 1.11.1.1
  548. log
  549. @Initial branch for Sprite server.
  550. @
  551. text
  552. @d17 1
  553. a17 1
  554. static char rcsid[] = "$Header: /sprite/src/cmds/prefix/RCS/prefix.c,v 1.11 92/03/25 15:53:12 shirriff Exp $ SPRITE (Berkeley)";
  555. @
  556.  
  557.  
  558. 1.10
  559. log
  560. @localPath doesn't have to be a remote link with -x option
  561. @
  562. text
  563. @d17 1
  564. a17 1
  565. static char rcsid[] = "$Header: /sprite/src/cmds/prefix/RCS/prefix.c,v 1.9 91/10/25 15:57:01 rab Exp Locker: rab $ SPRITE (Berkeley)";
  566. d43 1
  567. d69 2
  568. d194 3
  569. a196 1
  570.     validateLocalPath(localPath, 1);
  571. d281 3
  572. a283 1
  573.         validateLocalPath(localPath, 0);
  574. @
  575.  
  576.  
  577. 1.9
  578. log
  579. @lstat the link to make sure it exists before adding it.
  580. @
  581. text
  582. @d17 1
  583. a17 1
  584. static char rcsid[] = "$Header: /sprite/src/cmds/prefix/RCS/prefix.c,v 1.8 91/08/26 21:00:46 rab Exp Locker: rab $ SPRITE (Berkeley)";
  585. d31 1
  586. a31 1
  587. static void validateLocalPath _ARGS_ ((char *path));
  588. d191 1
  589. a191 1
  590.     validateLocalPath(localPath);
  591. d271 6
  592. a276 1
  593.         validateLocalPath(localPath);
  594. d417 1
  595. a417 1
  596.  *      It must be an already existing remote link.
  597. d429 1
  598. a429 1
  599. validateLocalPath(path)
  600. d431 1
  601. d451 1
  602. a451 1
  603.     if ((statBuf.st_mode & S_IFMT) != S_IFRLNK) {
  604. @
  605.  
  606.  
  607. 1.8
  608. log
  609. @Ensure that if the -l option is used, it must specify an absolute path
  610. to an existing remote link.
  611. @
  612. text
  613. @d17 1
  614. a17 1
  615. static char rcsid[] = "$Header: /sprite/src/cmds/prefix/RCS/prefix.c,v 1.7 91/08/26 18:11:05 brent Exp Locker: rab $ SPRITE (Berkeley)";
  616. d429 3
  617. a431 2
  618.     if (path == (char *) NULL) {
  619.     fprintf(stderr, "You must specify a local directory with -l\n");
  620. d436 2
  621. a437 1
  622.         "%s is not an absolute path.  It must start with '/'\n", path);
  623. d440 3
  624. a442 2
  625.     if (stat(path, &statBuf) < 0) {
  626.     fprintf(stderr, "Cannot stat %s:  %s\n", path, strerror(errno));
  627. d446 2
  628. a447 1
  629.     fprintf(stderr, "%s is not a remote link.\n", localPath);
  630. @
  631.  
  632.  
  633. 1.7
  634. log
  635. @*** empty log message ***
  636. @
  637. text
  638. @d17 1
  639. a17 1
  640. static char rcsid[] = "$Header: /a/newcmds/prefix/RCS/prefix.c,v 1.6 89/06/19 14:29:31 jhh Exp $ SPRITE (Berkeley)";
  641. d28 1
  642. d30 6
  643. d40 14
  644. a53 14
  645. int print = 0;
  646. int readOnly = 0;
  647. int localAccess = 0;
  648. char *loadedPrefix = (char *) NULL;
  649. char *deviceName = (char *) NULL;
  650. char *unmountName = (char *) NULL;
  651. char *exportedPrefix = (char *) NULL;
  652. char *clearedPrefix = (char *) NULL;
  653. char *deletedPrefix = (char *) NULL;
  654. char *Prefix = (char *) NULL;
  655. char *localPath = (char *) NULL;
  656. char *addHostName = NULL;
  657. char *delHostName = NULL;
  658. char *serverName = NULL;
  659. d55 1
  660. a55 1
  661. Option optionArray[] = {
  662. d83 2
  663. d116 1
  664. d191 1
  665. a191 5
  666.     if (localPath == (char *)NULL) {
  667.         fprintf(stderr, "Need -l {local directory} with -M\n");
  668.         Opt_PrintUsage(argv[0], optionArray, Opt_Number(optionArray));
  669.         exit(1);
  670.     }
  671. a267 4
  672.     } else if (localPath == (char *) NULL) {
  673.         fprintf(stderr, "Also specify a local directory with -l\n");
  674.         Opt_PrintUsage(argv[0], optionArray, Opt_Number(optionArray));
  675.         exit(1);
  676. d270 3
  677. a272 1
  678.     
  679. d348 1
  680. d350 1
  681. a350 1
  682.     register Fs_Prefix *prefixPtr;
  683. d404 45
  684. @
  685.  
  686.  
  687. 1.6
  688. log
  689. @added -s option, also changed -[hH] to use names as well as ids.
  690. @
  691. text
  692. @d17 1
  693. a17 1
  694. static char rcsid[] = "$Header: /a/newcmds/prefix/RCS/prefix.c,v 1.5 88/10/31 09:38:50 brent Exp Locker: jhh $ SPRITE (Berkeley)";
  695. a207 1
  696.     clearedPrefix = unmountName;
  697. @
  698.  
  699.  
  700. 1.5
  701. log
  702. @Added in attachDisk functionality
  703. @
  704. text
  705. @d17 1
  706. a17 1
  707. static char rcsid[] = "$Header: /a/newcmds/prefix/RCS/prefix.c,v 1.4 88/09/12 13:32:19 brent Exp Locker: brent $ SPRITE (Berkeley)";
  708. d44 3
  709. a46 2
  710. int addHostID = -1;
  711. int delHostID = -1;
  712. d53 2
  713. d67 4
  714. a70 4
  715.     {OPT_INT,      "h", (char *) &addHostID,
  716.     "Next argument is host to add to export list"},
  717.     {OPT_INT,      "H", (char *) &delHostID,
  718.     "Next argument is host to delete from export list"},
  719. d98 8
  720. a105 2
  721.     register ReturnStatus status = SUCCESS;    /* status of system calls */
  722.     int flags;
  723. d120 39
  724. a158 1
  725.  
  726. d163 1
  727. a163 1
  728.      *    A prefix in the prefix table causes a broadcast to find the
  729. d165 2
  730. d168 6
  731. a173 2
  732.     status = Fs_Command(FS_PREFIX_LOAD, strlen(loadedPrefix) + 1,
  733.         loadedPrefix);
  734. d182 1
  735. a182 1
  736.         fprintf(stderr, "%s: need -l {local directory} with -M\n");
  737. @
  738.  
  739.  
  740. 1.4
  741. log
  742. @Added printing of export lists
  743. @
  744. text
  745. @d17 1
  746. a17 1
  747. static char rcsid[] = "$Header: prefix.c,v 1.3 88/08/07 17:37:10 ouster Exp $ SPRITE (Berkeley)";
  748. d34 2
  749. d37 2
  750. d48 24
  751. a71 8
  752.     {OPT_TRUE,   "p", (char *) &print, "Print the prefix table or export list"},
  753.     {OPT_STRING, "a", (char *) &loadedPrefix, "Next argument contains prefix to add"},
  754.     {OPT_STRING, "l", (char *) &localPath, "Next argument contains directory to export (use with -x)"},
  755.     {OPT_STRING, "x", (char *) &exportedPrefix, "Next argument contains exported prefix (use with -p, -l, or -[hH])"},
  756.     {OPT_INT,      "h", (char *) &addHostID, "Next argument contains host to add to export list"},
  757.     {OPT_INT,      "H", (char *) &delHostID, "Next argument contains host to delete from export list"},
  758.     {OPT_STRING, "c", (char *) &clearedPrefix, "Next argument contains prefix to clear handle for"},
  759.     {OPT_STRING, "d", (char *) &deletedPrefix, "Next argument contains prefix to delete altogether"},
  760. d96 1
  761. d108 1
  762. a108 1
  763.     fprintf(stderr, "Type \"%s -help\" for help.\n", argv[0]);
  764. d127 30
  765. d159 3
  766. a161 1
  767.  
  768. a233 4
  769.     } else if (localPath != (char *) NULL) {
  770.     fprintf(stderr, "Also specify an exported prefix with -x\n");
  771.     Opt_PrintUsage(argv[0], optionArray, Opt_Number(optionArray));
  772.     exit(1);
  773. @
  774.  
  775.  
  776. 1.3
  777. log
  778. @Eliminated "-D" switch, since it's embodied in df now.
  779. @
  780. text
  781. @d4 1
  782. a4 1
  783.  *    Program to manipulate the prefix table.
  784. d17 1
  785. a17 1
  786. static char rcsid[] = "$Header: prefix.c,v 1.1 88/08/07 14:43:03 ouster Exp $ SPRITE (Berkeley)";
  787. d38 1
  788. d44 1
  789. a44 1
  790.     {OPT_TRUE,   "p", (char *) &print, "Print the prefix table"},
  791. d47 1
  792. a47 1
  793.     {OPT_STRING, "x", (char *) &exportedPrefix, "Next argument contains name of xported prefix (use with -l or -[hH])"},
  794. d132 27
  795. a158 4
  796.     Fs_TwoPaths args;
  797.  
  798.     if (localPath == (char *) NULL) {
  799.         fprintf(stderr, "Specify a local directory with -l\n");
  800. d161 19
  801. a180 17
  802.  
  803.     /*
  804.      * Export a prefix.  This is used on a server to explicitly
  805.      * export a local directory under some prefix.
  806.      */
  807.  
  808.     args.pathLen1 = strlen(localPath) + 1;
  809.     args.path1 = localPath;
  810.     args.pathLen2 = strlen(exportedPrefix) + 1;
  811.     args.path2 = exportedPrefix;
  812.  
  813.     status = Fs_Command(FS_PREFIX_EXPORT, sizeof(Fs_TwoPaths), &args);
  814.     if (status != SUCCESS) {
  815.         fprintf(stderr, "%s couldn't export prefix: %s.\n",
  816.             argv[0], Stat_GetMsg(status));
  817.         exit(1);
  818.     }
  819. d182 1
  820. a182 1
  821.     fprintf(stderr, "Specify an exported prefix with -x\n");
  822. @
  823.  
  824.  
  825. 1.2
  826. log
  827. @Handle "df" alias.
  828. @
  829. text
  830. @a33 1
  831. int diskInfo = 0;
  832. a43 2
  833.     {OPT_TRUE,   "D", (char *) &diskInfo,
  834.         "Print out disk space information about all domains"},
  835. a74 1
  836.     char *p;
  837. d76 2
  838. a77 7
  839.     /*
  840.      * If invoked under the name "df", just print disk utilization info.
  841.      */
  842.  
  843.     p = strrchr(argv[0], '/');
  844.     if (p == NULL) {
  845.     p = argv[0];
  846. d79 2
  847. a80 1
  848.     p += 1;
  849. a81 10
  850.     if (strcmp(p, "df") == 0) {
  851.     diskInfo = 1;
  852.     } else {
  853.     if (argc == 1) {
  854.         print = 1;
  855.     } else {
  856.         argc = Opt_Parse(argc, argv, optionArray, Opt_Number(optionArray),
  857.             OPT_ALLOW_CLUSTERING);
  858.     }
  859.     }
  860. a196 13
  861.     } else if (diskInfo) {
  862.     register int index;
  863.     Fs_Prefix prefix;
  864.  
  865.     printf("%-12s %-8s %10s %10s %10s %10s\n",
  866.         "Prefix", "Server", "KBytes", "Used", "Avail", "Capacity");
  867.     for (index = 0 ; status == SUCCESS; index++) {
  868.         bzero((char *) &prefix, sizeof(Fs_Prefix));
  869.         status = Sys_Stats(SYS_FS_PREFIX_STATS, index, (Address)&prefix);
  870.         if (status == SUCCESS) {
  871.         PrintDiskInfo(&prefix);
  872.         }
  873.     }
  874. d200 16
  875. a270 58
  876. }
  877.  
  878. PrintDiskInfo(prefixPtr)
  879.     register Fs_Prefix *prefixPtr;
  880. {
  881.     static char serverName[32];
  882.     static int  prevServerID = -1;
  883.     int        inUse;
  884.     int        free;
  885.     int        avail;
  886.     Host_Entry  *host;
  887.  
  888.     printf("%-12s", prefixPtr->prefix);
  889.  
  890.     if (prefixPtr->serverID > 0) {
  891.  
  892.     /*
  893.      * If the server ID is the same as the previous entry's ID, then
  894.      * we can reuse serverName and save a call to Host_ByID.
  895.      */
  896.     if (prefixPtr->serverID == prevServerID) {
  897.         printf(" %-8s", serverName);
  898.     } else {
  899.         host = Host_ByID(prefixPtr->serverID);
  900.         if (host != (Host_Entry *)NULL) {
  901.         register int charCnt;
  902.         for (charCnt = 0 ; charCnt < sizeof(serverName) ; charCnt++) {
  903.             if (host->name[charCnt] == '.' ||
  904.             host->name[charCnt] == '\0') {
  905.             serverName[charCnt] = '\0';
  906.             break;
  907.             } else {
  908.             serverName[charCnt] = host->name[charCnt];
  909.             }
  910.         }
  911.         serverName[sizeof(serverName)-1] = '\0';
  912.         printf(" %-8s", serverName);
  913.         prevServerID = prefixPtr->serverID;
  914.         } else {
  915.         printf(" (%d)", prefixPtr->serverID);
  916.         }
  917.     }
  918.     } else {
  919.     printf(" %-8s", "(none)");
  920.     }
  921.     if (prefixPtr->domainInfo.maxKbytes <= 0) {
  922.     printf("\n");
  923.     return;
  924.     }
  925.  
  926.     free = prefixPtr->domainInfo.freeKbytes - 
  927.                 (0.1 * prefixPtr->domainInfo.maxKbytes);
  928.     avail = 0.9 * prefixPtr->domainInfo.maxKbytes;
  929.     inUse = avail - free;
  930.  
  931.     printf(" %10d %10d %10d %7d%%\n", 
  932.     prefixPtr->domainInfo.maxKbytes, inUse,    free >= 0 ? free : 0,
  933.     (int) (100.0 * (inUse / (float) avail)));
  934. @
  935.  
  936.  
  937. 1.1
  938. log
  939. @Initial revision
  940. @
  941. text
  942. @d17 1
  943. a17 1
  944. static char rcsid[] = "$Header: prefix.c,v 1.11 88/07/13 11:45:41 nelson Exp $ SPRITE (Berkeley)";
  945. d78 1
  946. d80 7
  947. a86 2
  948.     if (argc == 1) {
  949.     print = TRUE;
  950. d88 11
  951. a98 2
  952.     argc = Opt_Parse(argc, argv, optionArray, Opt_Number(optionArray),
  953.         OPT_ALLOW_CLUSTERING);
  954. @
  955.